﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;
using KC.DataAccess.MV;

namespace KC.Presentation.Mv8CMS
{
	public partial class PostManager : Form
	{
		public PostManager()
		{
			InitializeComponent();
		}

		private void PostManager_Load(object sender, EventArgs e)
		{
			RefreshPosts();
		}

		/// <summary>User double-clicked a cell. Open its corresponding Post.</summary>
		private void dgPosts_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			// Used Retry here because it most nearly resembles "Need to refresh"
			if (new PostDesigner((int)(dgPosts.Rows[e.RowIndex].Cells[0].Value)).ShowDialog() == DialogResult.Retry)
				RefreshPosts();
		}
		/// <summary>Refreshes Post list</summary>
		private void RefreshPosts()
		{
			// I went with a datatable here because the Linq lookup was slooooow.
			DataTable dt = KC.DataAccess.MV.Utils.GetPostManagerPosts();
			dgPosts.DataSource = dt;
			dgPosts.Columns[0].Width = 50;
			dgPosts.Columns[1].Width = 200;
			dgPosts.Columns[2].Width = 25;
			dgPosts.Columns[3].Width = 500;
		}

	}
}
